package com.wsl.sale.service;

import com.wsl.sale.pojo.Order;
import com.wsl.sale.pojo.Person;
import com.wsl.sale.repository.OrderRepository;
import com.wsl.sale.repository.PersonRepository;
import com.wsl.sale.utils.SnowFlakeIdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PersonService {
    @Autowired
    PersonRepository personRepository;

    @Autowired
    OrderRepository orderRepository;

    @RequestMapping("save")
    public String save(){
        SnowFlakeIdGenerator snowFlakeIdGenerator = new SnowFlakeIdGenerator(1, 1);
        Person person = new Person();
        person.setPersonid(snowFlakeIdGenerator.nextId());
        person.setName("王书亮");
        personRepository.save(person);
        return person.toString();
    }
    @RequestMapping("/add")
    public String add(){
        final SnowFlakeIdGenerator snowFlakeIdGenerator = new SnowFlakeIdGenerator(1, 1);
        for (int i = 0; i < 10; i++) {
            Order order = new Order();
            order.setOrderId(snowFlakeIdGenerator.nextId());
            order.setUserId(snowFlakeIdGenerator.nextId());
            orderRepository.save(order);
        }
        return "分库分表添加成功";

    }


}
